#include <iostream>
#include "tree.h"
#include "tree.cpp"
#include <fstream>
#include <map>
using namespace std;

class cKodek{

    public:

        int iRozmiar_alfabetu;
        void vHuffman_koder();
        void vHuffman_dekoder();
        void vHuffman_koduj(char , fstream );
        void vHuffman_dekoduj(fstream file_handle);
        void vArytmetyczne_koder();
        void vArytmetyczne_dekoder();
        fstream file_handle;
        map<string, char> tk_bin2char; //tablica kodow binarnych do char
        map<char, string> tk_char2bin; //tablica kodow char do binarnych
        cKodek(int rozmiar);
        void vInicjalizuj_model();
        void vUpdate_model(char a, cTree *drzewo);
};

void cKodek::vHuffman_koder()
{
    file_handle.open("in.txt",ios::in);
    fstream plik;
    if (file_handle.is_open())
    {
        cTree drzewo(iRozmiar_alfabetu);
        vInicjalizuj_model();

        vUpdate_model('a', &drzewo);

    }
    else{
        cout <<"Nie udalo sie otworzyc pliku \n";
        return ;
    }
}
void cKodek::vHuffman_koduj(char a,fstream file)
{

}
cKodek::cKodek(int rozmiar){
    iRozmiar_alfabetu = rozmiar;
}


void cKodek::vUpdate_model(char a, cTree *drzewo)
{
    //cout << drzewo->search(drzewo->get_head(), a);
    drzewo->add_to_tree('a');
    drzewo->add_to_tree('a');
    drzewo->add_to_tree('r');
    drzewo->add_to_tree('d');
    drzewo->add_to_tree('v');
    drzewo->InOrder();
  //  cout<< drzewo->search(drzewo->get_head(), 'a');
//    cout << drzewo->search(drzewo->get_head(), 'g', 0);
}

void cKodek::vInicjalizuj_model()
{


    tk_bin2char["0"]='\0';
    tk_bin2char["1"]='\1';
    tk_bin2char["10"]='\2';
    tk_bin2char["11"]='\3';
    tk_bin2char["100"]='\4';
    tk_bin2char["101"]='\5';
    tk_bin2char["110"]='\6';
    tk_bin2char["111"]='\7';
    tk_bin2char["1000"]='\10';
    tk_bin2char["1001"]='\11';
    tk_bin2char["1010"]='\12';
    tk_bin2char["1011"]='\13';
    tk_bin2char["1100"]='\14';
    tk_bin2char["1101"]='\15';
    tk_bin2char["1110"]='\16';
    tk_bin2char["1111"]='\17';
    tk_bin2char["10000"]='\20';
    tk_bin2char["10001"]='\21';
    tk_bin2char["10010"]='\22';
    tk_bin2char["10011"]='\23';
    tk_bin2char["10100"]='\24';
    tk_bin2char["10101"]='\25';
    tk_bin2char["10110"]='\26';
    tk_bin2char["10111"]='\27';
    tk_bin2char["11000"]='\30';
    tk_bin2char["11001"]='\31';
    tk_bin2char["11010"]='\32';
    tk_bin2char["11011"]='\33';
    tk_bin2char["11100"]='\34';
    tk_bin2char["11101"]='\35';
    tk_bin2char["11110"]='\36';
    tk_bin2char["11111"]='\37';
    tk_bin2char["100000"]='\40';
    tk_bin2char["100001"]='\41';
    tk_bin2char["100010"]='\42';
    tk_bin2char["100011"]='\43';
    tk_bin2char["100100"]='\44';
    tk_bin2char["100101"]='\45';
    tk_bin2char["100110"]='\46';
    tk_bin2char["100111"]='\47';
    tk_bin2char["101000"]='\50';
    tk_bin2char["101001"]='\51';
    tk_bin2char["101010"]='\52';
    tk_bin2char["101011"]='\53';
    tk_bin2char["101100"]='\54';
    tk_bin2char["101101"]='\55';
    tk_bin2char["101110"]='\56';
    tk_bin2char["101111"]='\57';
    tk_bin2char["110000"]='\60';
    tk_bin2char["110001"]='\61';
    tk_bin2char["110010"]='\62';
    tk_bin2char["110011"]='\63';
    tk_bin2char["110100"]='\64';
    tk_bin2char["110101"]='\65';
    tk_bin2char["110110"]='\66';
    tk_bin2char["110111"]='\67';
    tk_bin2char["111000"]='\70';
    tk_bin2char["111001"]='\71';
    tk_bin2char["111010"]='\72';
    tk_bin2char["111011"]='\73';
    tk_bin2char["111100"]='\74';
    tk_bin2char["111101"]='\75';
    tk_bin2char["111110"]='\76';
    tk_bin2char["111111"]='\77';
    tk_bin2char["1000000"]='\100';
    tk_bin2char["1000001"]='\101';
    tk_bin2char["1000010"]='\102';
    tk_bin2char["1000011"]='\103';
    tk_bin2char["1000100"]='\104';
    tk_bin2char["1000101"]='\105';
    tk_bin2char["1000110"]='\106';
    tk_bin2char["1000111"]='\107';
    tk_bin2char["1001000"]='\110';
    tk_bin2char["1001001"]='\111';
    tk_bin2char["1001010"]='\112';
    tk_bin2char["1001011"]='\113';
    tk_bin2char["1001100"]='\114';
    tk_bin2char["1001101"]='\115';
    tk_bin2char["1001110"]='\116';
    tk_bin2char["1001111"]='\117';
    tk_bin2char["1010000"]='\120';
    tk_bin2char["1010001"]='\121';
    tk_bin2char["1010010"]='\122';
    tk_bin2char["1010011"]='\123';
    tk_bin2char["1010100"]='\124';
    tk_bin2char["1010101"]='\125';
    tk_bin2char["1010110"]='\126';
    tk_bin2char["1010111"]='\127';
    tk_bin2char["1011000"]='\130';
    tk_bin2char["1011001"]='\131';
    tk_bin2char["1011010"]='\132';
    tk_bin2char["1011011"]='\133';
    tk_bin2char["1011100"]='\134';
    tk_bin2char["1011101"]='\135';
    tk_bin2char["1011110"]='\136';
    tk_bin2char["1011111"]='\137';
    tk_bin2char["1100000"]='\140';
    tk_bin2char["1100001"]='\141';
    tk_bin2char["1100010"]='\142';
    tk_bin2char["1100011"]='\143';
    tk_bin2char["1100100"]='\144';
    tk_bin2char["1100101"]='\145';
    tk_bin2char["1100110"]='\146';
    tk_bin2char["1100111"]='\147';
    tk_bin2char["1101000"]='\150';
    tk_bin2char["1101001"]='\151';
    tk_bin2char["1101010"]='\152';
    tk_bin2char["1101011"]='\153';
    tk_bin2char["1101100"]='\154';
    tk_bin2char["1101101"]='\155';
    tk_bin2char["1101110"]='\156';
    tk_bin2char["1101111"]='\157';
    tk_bin2char["1110000"]='\160';
    tk_bin2char["1110001"]='\161';
    tk_bin2char["1110010"]='\162';
    tk_bin2char["1110011"]='\163';
    tk_bin2char["1110100"]='\164';
    tk_bin2char["1110101"]='\165';
    tk_bin2char["1110110"]='\166';
    tk_bin2char["1110111"]='\167';
    tk_bin2char["1111000"]='\170';
    tk_bin2char["1111001"]='\171';
    tk_bin2char["1111010"]='\172';
    tk_bin2char["1111011"]='\173';
    tk_bin2char["1111100"]='\174';
    tk_bin2char["1111101"]='\175';
    tk_bin2char["1111110"]='\176';
    tk_bin2char["1111111"]='\177';

    tk_char2bin['\0']="0";
    tk_char2bin['\1']="1";
    tk_char2bin['\2']="10";
    tk_char2bin['\3']="11";
    tk_char2bin['\4']="100";
    tk_char2bin['\5']="101";
    tk_char2bin['\6']="110";
    tk_char2bin['\7']="111";
    tk_char2bin['\10']="1000";
    tk_char2bin['\11']="1001";
    tk_char2bin['\12']="1010";
    tk_char2bin['\13']="1011";
    tk_char2bin['\14']="1100";
    tk_char2bin['\15']="1101";
    tk_char2bin['\16']="1110";
    tk_char2bin['\17']="1111";
    tk_char2bin['\20']="10000";
    tk_char2bin['\21']="10001";
    tk_char2bin['\22']="10010";
    tk_char2bin['\23']="10011";
    tk_char2bin['\24']="10100";
    tk_char2bin['\25']="10101";
    tk_char2bin['\26']="10110";
    tk_char2bin['\27']="10111";
    tk_char2bin['\30']="11000";
    tk_char2bin['\31']="11001";
    tk_char2bin['\32']="11010";
    tk_char2bin['\33']="11011";
    tk_char2bin['\34']="11100";
    tk_char2bin['\35']="11101";
    tk_char2bin['\36']="11110";
    tk_char2bin['\37']="11111";
    tk_char2bin['\40']="100000";
    tk_char2bin['\41']="100001";
    tk_char2bin['\42']="100010";
    tk_char2bin['\43']="100011";
    tk_char2bin['\44']="100100";
    tk_char2bin['\45']="100101";
    tk_char2bin['\46']="100110";
    tk_char2bin['\47']="100111";
    tk_char2bin['\50']="101000";
    tk_char2bin['\51']="101001";
    tk_char2bin['\52']="101010";
    tk_char2bin['\53']="101011";
    tk_char2bin['\54']="101100";
    tk_char2bin['\55']="101101";
    tk_char2bin['\56']="101110";
    tk_char2bin['\57']="101111";
    tk_char2bin['\60']="110000";
    tk_char2bin['\61']="110001";
    tk_char2bin['\62']="110010";
    tk_char2bin['\63']="110011";
    tk_char2bin['\64']="110100";
    tk_char2bin['\65']="110101";
    tk_char2bin['\66']="110110";
    tk_char2bin['\67']="110111";
    tk_char2bin['\70']="111000";
    tk_char2bin['\71']="111001";
    tk_char2bin['\72']="111010";
    tk_char2bin['\73']="111011";
    tk_char2bin['\74']="111100";
    tk_char2bin['\75']="111101";
    tk_char2bin['\76']="111110";
    tk_char2bin['\77']="111111";
    tk_char2bin['\100']="1000000";
    tk_char2bin['\101']="1000001";
    tk_char2bin['\102']="1000010";
    tk_char2bin['\103']="1000011";
    tk_char2bin['\104']="1000100";
    tk_char2bin['\105']="1000101";
    tk_char2bin['\106']="1000110";
    tk_char2bin['\107']="1000111";
    tk_char2bin['\110']="1001000";
    tk_char2bin['\111']="1001001";
    tk_char2bin['\112']="1001010";
    tk_char2bin['\113']="1001011";
    tk_char2bin['\114']="1001100";
    tk_char2bin['\115']="1001101";
    tk_char2bin['\116']="1001110";
    tk_char2bin['\117']="1001111";
    tk_char2bin['\120']="1010000";
    tk_char2bin['\121']="1010001";
    tk_char2bin['\122']="1010010";
    tk_char2bin['\123']="1010011";
    tk_char2bin['\124']="1010100";
    tk_char2bin['\125']="1010101";
    tk_char2bin['\126']="1010110";
    tk_char2bin['\127']="1010111";
    tk_char2bin['\130']="1011000";
    tk_char2bin['\131']="1011001";
    tk_char2bin['\132']="1011010";
    tk_char2bin['\133']="1011011";
    tk_char2bin['\134']="1011100";
    tk_char2bin['\135']="1011101";
    tk_char2bin['\136']="1011110";
    tk_char2bin['\137']="1011111";
    tk_char2bin['\140']="1100000";
    tk_char2bin['\141']="1100001";
    tk_char2bin['\142']="1100010";
    tk_char2bin['\143']="1100011";
    tk_char2bin['\144']="1100100";
    tk_char2bin['\145']="1100101";
    tk_char2bin['\146']="1100110";
    tk_char2bin['\147']="1100111";
    tk_char2bin['\150']="1101000";
    tk_char2bin['\151']="1101001";
    tk_char2bin['\152']="1101010";
    tk_char2bin['\153']="1101011";
    tk_char2bin['\154']="1101100";
    tk_char2bin['\155']="1101101";
    tk_char2bin['\156']="1101110";
    tk_char2bin['\157']="1101111";
    tk_char2bin['\160']="1110000";
    tk_char2bin['\161']="1110001";
    tk_char2bin['\162']="1110010";
    tk_char2bin['\163']="1110011";
    tk_char2bin['\164']="1110100";
    tk_char2bin['\165']="1110101";
    tk_char2bin['\166']="1110110";
    tk_char2bin['\167']="1110111";
    tk_char2bin['\170']="1111000";
    tk_char2bin['\171']="1111001";
    tk_char2bin['\172']="1111010";
    tk_char2bin['\173']="1111011";
    tk_char2bin['\174']="1111100";
    tk_char2bin['\175']="1111101";
    tk_char2bin['\176']="1111110";
    tk_char2bin['\177']="1111111";

//cout << tk_bin2char["1000100"] <<tk_bin2char["1010101"]<<tk_bin2char["1010000"] <<tk_bin2char["o"] <<tk_bin2char["100001"] <<"\n";

}
int main()
{
    cKodek aaa(127);

    aaa.vHuffman_koder();

}
